package org.example.bookssystem.Dao;

import org.example.bookssystem.model.BookInfo;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:做渐进主义的改良派,不做完没注意的速成派
 * User: XALEXC
 * Date: 2024-10-23
 * Time: 19:39
 */

@Component
public class BookDao {

    public List<BookInfo> mockData() {
        // 优化小Tip: 对于已知的数据量,或者大概知道这个集合的数据量时,创建List时,建议制定初始化容量
        List<BookInfo>bookInfos=new ArrayList<>(15);
        for (int i = 0; i < 15; i++) {
            BookInfo bookInfo=new BookInfo();
            bookInfo.setId(i);
            bookInfo.setBookName("图书"+i);
            bookInfo.setAuthor("作者"+i);
            bookInfo.setPublish("出版社"+i);
            bookInfo.setPrice(new BigDecimal(new Random().nextInt(100)));
            bookInfo.setCount(new Random().nextInt(200));
            bookInfo.setStatus(i%5==0?0:1);
            bookInfos.add(bookInfo);
        }
        return bookInfos;
    }

}
